000100******************************************************************
000200*PROGRAM : Add course to the ISAM FILE                           *
000300*AUTHOR  : Elijah Yang                                           *
000400******************************************************************
000500 IDENTIFICATION DIVISION.
000600 PROGRAM-ID. CRS-A.
000700 ENVIRONMENT DIVISION.
000800     SELECT IOFILE       ASSIGN TO "BLDGMST.DAT"
000900                         ORGANIZATION  IS INDEXED
001000                         ACCESS        IS RANDOM
001100                         RECORD KEY    IS BLDG-CODE
001200                         FILE STATUS   IS WS-STAT.
001300
001400 DATA DIVISION.
001500 FILE SECTION.
001600 FD  IOFILE.
001700 01  OUT-REC.
001800     03  BLDG-CODE       PIC X(11).
001900     03  CAPACITY        PIC 9(3).
002000
002100     03  ACTIVE          PIC X.
002200
002300 WORKING-STORAGE SECTION.
002400 01  WS-STAT             PIC XX.
002500 01  WS-EOF              PIC X VALUE 'N'.
002600 01  WS-BLDG-CODE           PIC X(11).
002700 01  WS-CAPACITY         PIC 9(3).
002800
002900 01  WS-A            PIC X.
003000 01  WS-DATE.
003100     03  WS-YEAR         PIC 99.
003200     03  WS-MONTH        PIC 99.
003300     03  WS-DAY          PIC 99.
003400 01  WS-ERR              PIC X VALUE 'N'.
003500 01  WS-CONT             PIC X VALUE 'Y'.
003600
003700 SCREEN SECTION.
003800 01  INPUT-SCRN.
003900         05  BLANK SCREEN.
004000         05  LINE 1  COL 01  VALUE "ADD BUILDING".
004100         05          COL 73  PIC 9(2) FROM WS-MONTH.
004200         05          COL 75  VALUE "/".
004300         05          COL 76  PIC 9(2) FROM WS-DAY.
004400         05          COL 78  VALUE "/".
004500         05          COL 79  PIC 9(2) FROM WS-YEAR.
004600         05  LINE 2  COL 37  VALUE "ADD COURSE".
004700         05  INPUT-CRS-ID-SCRN.
004800             10  LINE 4  COL 20  VALUE "BUILDING ID".
004900             10          COL 40  PIC X(11) TO WS-BLDG-CODE.
                   10  LINE 5  COL 20 VALUE "EX: BALDOR145A".
005000         05  INPUT-CRS-NAME-SCRN.
005100             10  LINE 6  COL 20  VALUE "CAPACITY".
005200             10          COL 40  PIC 9(3) TO WS-CAPACITY.
005300
005400
005500
005600         05  INPUT-CRS-A-SCRN.
005700             10  LINE 7  COL 20  VALUE "ACTIVATE (Y/N)?".
005800             10          COL 40  PIC X TO WS-A AUTO.
005900         05  LINE 11 COL 34  VALUE "(ENTER XXX TO EXIT)".
006000 01  ERROR-SCRN.
006100     03  BLANK SCREEN.
006200     03  LINE 12 COL 32 VALUE "ERROR ADDING RECORD".
006300     03  LINE 14 COL 32 VALUE "FILE STATUS:".
006400     03          COL 46 PIC XX FROM WS-STAT.
006500     03  LINE 15 COL 32 VALUE "RECORD KEY:".
006600     03          COL 46 PIC X(11) FROM BLDG-CODE.
006700     03  LINE 16 COL 32 VALUE "CONTINUE(Y/N)?".
006800     03          COL 47 PIC X TO WS-CONT AUTO.
006900
007000 01  SUCCESS-SCRN.
007100     03  BLANK SCREEN.
007200     03  LINE 12 COL 32 VALUE "RECORD ADDED SUCCESSFULLY".
007300     03  LINE 13 COL 32 VALUE "RECORD INFORMATION:".
007400     03  LINE 14 COL 32 VALUE "BUILDING ID".
007500     03          COL 46 PIC X(11) FROM BLDG-CODE.
007600     03  LINE 15 COL 32 VALUE "BUILDING CAPACITY".
007700     03          COL 46 PIC 9(3) FROM CAPACITY.
007800
007900     03  LINE 17 COL 32 VALUE "ACTIVATE?".
008000     03          COL 46 PIC X FROM ACTIVE.
008100     03  LINE 18 COL 32 VALUE "CONTINUE(Y/N)?".
008200     03          COL 47 PIC X TO WS-CONT AUTO.
008300
008400
008500 PROCEDURE DIVISION.
008600 100-MAIN.
008700     ACCEPT WS-DATE FROM DATE
008800     OPEN I-O IOFILE.
008900
009000     MOVE SPACES TO WS-BLDG-CODE
009100     MOVE ZEROS TO WS-CAPACITY
009200
009300     MOVE SPACES TO WS-A
009400     MOVE 'Y' TO WS-CONT
009500
009600     DISPLAY INPUT-SCRN
009700     ACCEPT INPUT-CRS-ID-SCRN
009800     PERFORM UNTIL WS-BLDG-CODE = 'XXX' OR WS-CONT = 'N'
009900         ACCEPT INPUT-CRS-NAME-SCRN
010000
010100         ACCEPT INPUT-CRS-A-SCRN
010200
010300         MOVE WS-BLDG-CODE      TO BLDG-CODE
010400         MOVE WS-CAPACITY    TO CAPACITY
010500
010600         MOVE WS-A       TO ACTIVE
010700
010800         MOVE 'N' TO WS-ERR
010900
011000         WRITE OUT-REC
011100             INVALID KEY MOVE 'Y' TO WS-ERR
011200         END-WRITE
011300
011400         IF WS-ERR = 'Y'
011500             DISPLAY ERROR-SCRN
011600             ACCEPT ERROR-SCRN
011700         ELSE
011800             DISPLAY SUCCESS-SCRN
011900             ACCEPT SUCCESS-SCRN
012000         END-IF
012100
012200         IF WS-CONT = 'Y'
012300             DISPLAY INPUT-SCRN
012400             MOVE SPACES TO WS-BLDG-CODE
012500             MOVE ZEROES TO WS-CAPACITY
012600
012700             MOVE SPACES TO WS-A
012800             ACCEPT INPUT-CRS-ID-SCRN
012900         END-IF
013000     END-PERFORM
013100     CLOSE IOFILE
013200     EXIT PROGRAM.
